/* JavaStreamWrapper.h
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#ifndef JAVASTREAMWRAPPER_H
#define JAVASTREAMWRAPPER_H

#include <iostream>
#include <string>
#include <vector>
#include <stdint.h>

class JavaStreamWrapper
{
	std::ostream&	os;

public:
	JavaStreamWrapper(std::ostream& stream);

	void writeBoolean(bool v);
	void writeByte(int v);
	void writeBytes(std::string& s);
	void writeChar(int c);
	void writeChars(std::string& s);
	void writeDouble(double v);
	void writeFloat(float v);
	void writeInt(int v);
	void writeLong(long v);
	void writeShort(int v);
	void writeUTF(std::string& str);

	static bool readBoolean(void *b);
	static int8_t readByte(void *b);
	static double readDouble(void *b);
	static float readFloat(void *b);
	static int32_t readInt(void *b);
	static int64_t readLong(void *b);
	static int16_t readShort(void *b);
	static uint8_t readUnsignedByte(void *b);
	static uint16_t readUnsignedShort(void *b);
	static std::string readUTF(void *b, int16_t len);
};

template <class T>
class JavaArrayWrapper
{
public:
	static void readArray(void *b, std::vector<T>& vector, ssize_t elem_size);
};

template <>
class JavaArrayWrapper <int8_t>
{
public:
	static void readArray(void *b, std::vector<int8_t>& vector, ssize_t elem_size);
};

template <>
class JavaArrayWrapper <uint8_t>
{
public:
	static void readArray(void *b, std::vector<uint8_t>& vector, ssize_t elem_size);
};

#endif
